﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FizzBuzz
{
    internal class NewsAgent
    {
        private string name;

        public NewsAgent(string agentName)
        {
            this.Name = agentName;
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public void NewsHandler(string news)
        {
            Console.WriteLine("NewsAgent:{0} : News: {1}", this.Name, news);
            throw new ArgumentException("Unable to handle news");
        }
    }

    internal class NewsPublisher
    {
        public delegate void NewsItemEventHandler(string news);

        public event NewsItemEventHandler NewsItem;

        public void FireEvent(string news)
        {
            if (news != null)
            {
                foreach (Delegate del in NewsItem.GetInvocationList())
                {
                    NewsItemEventHandler sink = (NewsItemEventHandler) del;
                    try
                    {
                        sink(news);
                    }
                    catch (ArgumentException e)
                    {
                        System.Console.WriteLine(e);
                    }
                }
            }
        }
    }

    internal class MyClass<T>
    {
        public delegate void GenericEventHandler(T t);

        public void SomeMethod(T t)
        {
        }
    }

    internal class Publisher
    {
        public delegate void NumberChangeDelegate(int number);

        public NumberChangeDelegate NumberChanged;

        public void setup()
        {
        }
    }

    internal class Subscriber
    {
        public void OnNumberChanged(int number)
        {
            Console.WriteLine("New number is:" + number);
        }
    }
}